package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-12-31 00:20
 **/
public class LeetCode507 {

    //数学
    public boolean checkPerfectNumber(int num) {
        return num == 6 || num == 28 || num == 496 || num == 8128 || num == 33550336;
    }

    //枚举优化
    /*public boolean checkPerfectNumber(int num) {
        if (num == 1) {
            return false;
        }

        int sum = 1;
        for (int d = 2; d * d <= num; ++d) {

            if (num % d == 0) {
                sum += d;
                //避免num为4,d为2时添加两次的情况
                if (d * d < num) {
                    sum += num / d;
                }
            }
        }
        return sum == num;
    }*/

    //枚举
    /*public boolean checkPerfectNumber(int num) {
        int sum = 0;
        for (int i = 0; i < num; ++i) {
            if (num % i == 0) {
                sum += i;
            }
        }

        return sum == num;
    }*/

}
